// 查询图片的id
if(getQueryString("secondId")){
    var secondId = getQueryString("secondId");
}
var params = {
    id:secondId
}
// 获取图片接口
var getData = {
   //获取图片接口
   getSelectImgInfo:function(){
       var successData = function(data){
            if(data.errorCode == 0){
                renderData.renderImg(data.data)
            }
       }
       return  web.doAjax(root.sroreinter.getAppScenePointByAppSceneId, 'post', params, successData);
   }
}

var renderData = {
    // 渲染图片
    renderImg:function(data){
        if(!!data){
            var imgUrl = data.imgUrl;
            var coordinate = data.coordinate;
            $("#pic").attr('src',imgUrl);
            renderData.renderShowMark(coordinate)
        }
    },
    // 图片小图标返显
    renderShowMark:function(ary){
        var newAry = [];
        $.each(ary,function(index,item){
            var obj = {};
            obj.location = item;
            newAry.push(obj)
        })
        var x,y;
        $.each(newAry,function(index,item){
            var newItem = item.location.split(',')
            x = newItem[0];
            y = newItem[1]
            var marksItem =
                ' <div class="marks" style="left:'+ x +';top:'+ y +';" data-type="'+newItem+'">' +
                ' <img src="../../../img/mark.png" alt="这是一个小图标"  class="mark">' +
                ' <span>'+newItem+'</span>'+
                ' </div>';
            $("#showPic").append(marksItem)
        })
        // 点击小图标将数据填入对应的位置
        $.each($(".marks"),function(index,item){
            $(item).on("click",function(){
                var location = $(this).attr("data-type");
                parent.callback(location)
                // 弹窗关闭
                parent.layer.closeAll();
            })
        })
    }
}
getData.getSelectImgInfo();
// 选取图片位置的操作
function selectPicLocation(){
    var picW = $("#pic").width(); //获取图片的宽度
    var picH = $("#pic").height(); //获取图片的高度
    var scaleX,scaleY,x,y;
    $("#pic").on('click',function(e){
        e = e || window.event;
        x = e.offsetX , y = e.offsetY;//相对于图片的偏移量也就是相对于图片的坐标位置
        //图片的坐标位置
        scaleX = x/picW;
        scaleY = y/picH;
        //拼接坐标点
        var point = x +'px'+ ',' + y + 'px'
        // 父级回传数据
        parent.callback(point)
        //弹窗关闭
        parent.layer.closeAll();
    })
}
selectPicLocation();